const button = document.querySelector('button');
const area = document.querySelector('input');

function search() {

  var inputText = area.value;
  var text = new XMLHttpRequest();
  text.open('get', 'https://restapi.amap.com/v3/weather/weatherInfo?key=3f6a51edf7357fc78b56484202b2a6c4&city=' + inputText);
  if (inputText == '') {
    alert('你还没有输入查询的地区');

  }


  text.onreadystatechange = function () {
    if (text.readyState == 4 && text.status == 200) {
      console.log(text.responseText);
      var responseObj = JSON.parse(text.responseText);
      var city = responseObj.lives[0].city;
      document.querySelector("#location").innerHTML = city;
      var temperature = responseObj.lives[0].temperature;
      document.querySelector("#temperature-degree").innerHTML = temperature + '°C';
      var weather = responseObj.lives[0].weather;
      document.querySelector("#weather-description").innerHTML = weather;
      var humidity = responseObj.lives[0].humidity;
      document.querySelector("#humidity").innerHTML = '相对湿度：' + humidity + '%';
      var windpower = responseObj.lives[0].windpower;
      document.querySelector("#wind").innerHTML = '风速：' + windpower + '公里/小时';
    }
  };

  text.send();
}